package Function;

import VWorldGameStudio.events.SayEvent;
import com.google.gson.Gson;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import utils.FCDataSingles;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Vector;

//npc的其他对话的都可以在这里编
public class BuildFCOtherNpcEventMain {
    private static final String ITEM_FILE = "./重装机兵V-数据-怪物.xls";
    private Gson gson = new Gson();
    Sheet sheet;

    public static void main(String[] args) {
        BuildFCOtherNpcEventMain main = new BuildFCOtherNpcEventMain();
        main.init();
    }


    private void init() {
        FCCharacterLibrary fcCharacterLibrary = new FCCharacterLibrary();
        FCEventLibrary fcEventLibrary = new FCEventLibrary();
        fcEventLibrary.loadEventData();

        try {
            int ids = 1;
            File file = new File(ITEM_FILE);
            // 创建输入流，读取Excel
            InputStream is = new FileInputStream(file.getAbsolutePath());
            // jxl提供的Workbook类
            Workbook wb = Workbook.getWorkbook(is);
            sheet = wb.getSheet(3);
            int npcId = 100;
            for (int i = 1; i < sheet.getRows(); i++) {
                Cell[] cells = sheet.getRow(i);
                if (cells != null && cells.length > 4) {
                    if (cells[2] == null || cells[2].getContents().isEmpty()) {
                        continue;
                    }
                    String NpcName = cells[2].getContents().trim();
                    //创建NPC
                    String pngName = cells[3].getContents().trim();
                    String actionName = cells[4].getContents().trim();
                    if (!pngName.endsWith("png")) {
                        pngName = pngName + ".png";
                    }
                    pngName = "./material/png/character/" + pngName;
                    String sayEventName = "null";
                    String eventID = "null";
                    if (cells[5] != null && !cells[5].getContents().isEmpty()) {
                        sayEventName = cells[5].getContents().trim();
                    }
                    if ("null".equals(sayEventName)) {
                        sayEventName = NpcName + "-Say";
                    }
                    SayEvent sayEvent = new SayEvent("say", sayEventName);
                    Vector<String> sl = new Vector<>();
                    Vector<String> sl2 = new Vector<>();
                    Vector<String> sl3 = new Vector<>();
                    for (int n = 6; n < 9; n++) {
                        if (n < cells.length) {
                            Cell cell_1 = cells[n];
                            if (cell_1 == null || cell_1.getContents().isEmpty()) {
                                continue;
                            }
                            String content = cell_1.getContents().trim();
                            if (content.length() > 1) {
                                sl.add(content);
                            }
                        }
                    }
                    for (int n = 9; n < 11; n++) {
                        if (n < cells.length) {
                            Cell cell_1 = cells[n];
                            if (cell_1 == null || cell_1.getContents().isEmpty()) {
                                continue;
                            }
                            String content = cell_1.getContents().trim();
                            if (content.length() > 1) {
                                sl2.add(content);
                            }
                        }
                    }
                    for (int n = 11; n < 12; n++) {
                        if (n < cells.length) {
                            Cell cell_1 = cells[n];
                            if (cell_1 == null || cell_1.getContents().isEmpty()) {
                                continue;
                            }
                            String content = cell_1.getContents().trim();
                            if (content.length() > 1) {
                                sl3.add(content);
                            }
                        }
                    }
                    sayEvent.addSayText(sl);
                    if(sl2.size() > 0){
                        sayEvent.addSayText(sl2);
                    }
                    if(sl3.size() > 0){
                        sayEvent.addSayText(sl3);
                    }
                    if (sl.size() > 0) {
                        FCDataSingles.getWriter().writeEventData(sayEvent);
                        eventID = sayEventName;
                    }
                    fcCharacterLibrary.registerCharater(false, npcId++, NpcName, "npc", actionName, eventID, pngName);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
